package com.yi.demo.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yi.entity.Record;
import com.yi.mapper.RecordMapper;
import com.yi.service.RecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {

    @Resource
    private RecordMapper recordMapper;

    /**
     * 查看流水记录的方法
     * PS：这个方法应该传入的是一个数据对象，但是这里偷懒使用了 Integer
     *
     * @param userId 用户 id
     * @return 流水记录的 list集合
     */
    @Override
    public List<Record> showRecord(Integer userId) {
        if (null == userId) {
            return null;
        }
        return recordMapper.selectList(
                Wrappers.<Record>lambdaQuery()
                        .eq(Record::getUserId, userId)
                        .orderByDesc(Record::getCreateTime));
    }
}
